//
//  MyPointsHeader.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/19.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class MyPointsHeader: UITableViewHeaderFooterView {

    // MARK: - life cycle
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        
        initBaseLayout()
        layoutPageSubviews()
        self.contentView.backgroundColor = UIColor.white
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - private method
    func initBaseLayout() {
        self.addSubview(iconView)
        self.addSubview(pointsLabel)
        self.addSubview(numLabel)
        self.addSubview(lineView)
        self.addSubview(messageLabel)
    }
    
    func layoutPageSubviews() {
        iconView.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(self).offset(30)
            make.width.height.equalTo(120)
        }
        
        pointsLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(iconView).offset(30)
            make.width.equalTo(29)
            make.height.equalTo(17)
        }
        
        numLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(pointsLabel.snp.bottom).offset(9)
            make.width.equalTo(80)
            make.height.equalTo(31)
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(0)
            make.bottom.equalTo(self).offset(-1)
            make.width.equalTo(SCREEN_WIDTH)
            make.height.equalTo(1)
        }
        
        messageLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(iconView.snp.bottom).offset(26)
            make.width.equalTo(152)
            make.height.equalTo(34)
        }
    }
    
    func configUI() {
        numLabel.text = "66666"
    }
    
    // MAKR: - setters and getters
    var _withoutPoints: Bool?
    var withoutPoints: Bool? {
        set {
            if newValue! {
                messageLabel.isHidden = false
            } else {
                messageLabel.isHidden = true
            }
        } get {
            return _withoutPoints
        }
    }
    var _iconView: UIView!
    var iconView: UIView {
        if _iconView == nil {
            _iconView = UIView()
            _iconView.backgroundColor = UIColor(hexString: "#B7A18A")
            _iconView.layer.masksToBounds = true
            _iconView.layer.cornerRadius = 60
        }
        return _iconView
    }
    
    var _pointsLabel: UILabel!
    var pointsLabel: UILabel {
        if _pointsLabel == nil {
            _pointsLabel = UILabel()
            _pointsLabel.font = UIFont(name: "PingFangSC-Regular", size: 14)
            _pointsLabel.textColor = UIColor(hexString: "#FFFFFF")
            _pointsLabel.textAlignment = .center
            _pointsLabel.text = "积分"
        }
        return _pointsLabel
    }
    
    var _numLabel: UILabel!
    var numLabel: UILabel {
        if _numLabel == nil {
            _numLabel = UILabel()
            _numLabel.font = UIFont(name: "HelveticaNeue", size: 26)
            _numLabel.textColor = UIColor(hexString: "#FFFFFF")
            _numLabel.textAlignment = .center
        }
        return _numLabel
    }
    
    var _lineView: UIView!
    var lineView: UIView {
        if _lineView == nil {
            _lineView = UIView()
            _lineView.backgroundColor = UIColor(hexString: "#DDDDDD")
        }
        return _lineView
    }
    
    var _messageLabel: UILabel!
    var messageLabel: UILabel {
        if _messageLabel == nil {
            _messageLabel = UILabel()
            _messageLabel.font = UIFont(name: "PingFangSC-Regular", size: 12)
            _messageLabel.textColor = UIColor(hexString: "#666666")
            _messageLabel.textAlignment = .center
            _messageLabel.text = "  你还没有获得过积分  " + "\n" + "购买商品每满50元奖励1积分"
            _messageLabel.numberOfLines = 2
        }
        return _messageLabel
    }
}
